# coding=utf8
import logging


service = None


def getSmsService():
    global service
    if service is None:
        service = SmsService()
    return service

appid = 1400073989

appkey = '3d8e1f3a876f16ec251a59e31765ffca'

sms_sign = "NITEWISH奈味"

template_id = 93960

sms_type = 0


class SmsService(object):
    def __init__(self):
        from qcloudsms_py import SmsSingleSender
        self.ssender = SmsSingleSender(appid, appkey)

    def send(self, phone_number, temp_id, params):
        from qcloudsms_py.httpclient import HTTPError
        try:
            result = self.ssender.send_with_param(86, phone_number,
                                             temp_id, params, sign=sms_sign, extend="",
                                             ext="")
            if result["result"] == 0:
                return True
            return False
        except HTTPError as e:
            return False
        except Exception as e:
            logging.error(e)
            return False
        

    
